<template>
  <el-container>
    <el-header>
      <div class="logo">
        <img src="../assets/logo.png" alt />管理系统
      </div>
      <el-button @click="singOut" type="info" plain round>退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="togger_row" @click="toggerCollapse">|||</div>
        <el-menu 
        :collapse-transition="false" 
        :collapse="isCollapse" 
        unique-opened 
        background-color="#323744" 
        text-color="#fff" 
        active-text-color="#23AAF2"
        router
        :default-active="$route.path">
          <el-submenu v-for="item in MenuList" :key="item.id" :index="item.id+''">
            <template slot="title">
              <i :class="icons[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item v-for="item1 in item.children" :key="item1.id" :index="'/'+item1.path">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{item1.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      MenuList: [],
      icons: {
        '125': 'el-icon-s-custom',
        '103': 'el-icon-s-tools',
        '101': 'el-icon-s-shop',
        '102': 'el-icon-s-goods',
        '145': 'el-icon-s-data'
      },
      isCollapse: false
    }
  },
  created() {
    this.getMenuList()
  },
  methods: {
    singOut() {
      this.$message.success('您已退出')
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList() {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status === 200) {
        this.MenuList = res.data
      }
    },
    toggerCollapse(){
      this.isCollapse = !this.isCollapse
    }
  },
}
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
  .el-header {
    background-color: #373c41;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .logo {
      color: #fff;
      font-size: 28px;
      height: 60px;
      img {
        height: 100%;
        vertical-align: middle;
        margin-right: 20px;
      }
    }
  }
  .el-container {
    .el-aside {
      background-color: #323744;
      transition: all 300ms ease;
      .el-menu {
        border-right: none;
      }
      .togger_row{
        background-color: #485164;
        text-align: center;
        color:#fff;
        font-size: 10px;
        line-height: 24px;
        letter-spacing: 0.2em;
        cursor: pointer;
      }
    }
    .el-main {
      background-color: #eaedf2;
    }
  }
}
</style>